home *** CD-ROM | disk | FTP | other *** search
/ 3D Games (Spidla) / 3dhry2.iso / Cube Drop 2001 1.0 / 3DFontView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-03-17  |  15.3 KB  |  739 lines

  1. /*
  2. Authors: David Nishimoto and Thomas Lee Young
  3. Website: http://www.listensoftware.com
  4. Program: Cube Drop
  5. */
  6.  
  7. #include "stdafx.h"
  8. #include "MainFrm.h"
  9. #include "3DFont.h"
  10.  
  11. #include "3DFontDoc.h"
  12. #include "3DFontView.h"
  13.  
  14. #include <time.h>
  15.  
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. #include "canvas.h"
  23. #include "matrix.h"
  24. #include "camera.h"
  25.  
  26. Canvas cvs(0,0,640,480,"Cube Space               Score: 0");
  27. Camera cam(PI/2.0, 12.0f, 90.0f);
  28. Matrix mat;
  29. BOOL gameOver = FALSE;
  30. BOOL pause = FALSE;
  31. BOOL autoRotate = FALSE;
  32. BOOL timersSet = FALSE;
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CMy3DFontView
  36.  
  37. IMPLEMENT_DYNCREATE(CMy3DFontView, CView)
  38.  
  39. BEGIN_MESSAGE_MAP(CMy3DFontView, CView)
  40.     //{{AFX_MSG_MAP(CMy3DFontView)
  41.     ON_WM_CREATE()
  42.     ON_WM_DESTROY()
  43.     ON_WM_SIZE()
  44.     ON_WM_TIMER()
  45.     ON_WM_KEYDOWN()
  46.     ON_COMMAND(ID_VIEW_AUTO, OnViewAuto)
  47.     ON_COMMAND(ID_VIEW_DEFAULT, OnViewDefault)
  48.     ON_COMMAND(ID_FILE_PAUSE, OnFilePause)
  49.     ON_COMMAND(ID_FILE_NEW, OnFileNew)
  50.     ON_COMMAND(ID_FILE_RESUME, OnFileResume)
  51.     ON_COMMAND(ID_VIEW_AUTOSTOP, OnViewAutostop)
  52.     //}}AFX_MSG_MAP
  53.     // Standard printing commands
  54. END_MESSAGE_MAP()
  55.  
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CMy3DFontView construction/destruction
  58.  
  59. CMy3DFontView::CMy3DFontView()
  60. {
  61.     // TODO: add construction code here
  62.     m_shininess = 10.0f;
  63.     m_Lightposition[0] = 100.0f;
  64.     m_Lightposition[1] = 0.0f;
  65.     m_Lightposition[2] = 0.0f;
  66.     m_Lightposition[3] = 0.0f;
  67.     m_Lightspecular[0] = 0.3f;
  68.     m_Lightspecular[1] = 0.3f;
  69.     m_Lightspecular[2] = 0.1f;
  70.     m_Lightspecular[3] = 1.0f;
  71.     m_Lightdiffuse[0] = 0.1f;
  72.     m_Lightdiffuse[1] = 0.1f;
  73.     m_Lightdiffuse[2] = 0.1f;
  74.     m_Lightdiffuse[3] = 1.0f;
  75.     m_Lightambient[0] = 0.3f;
  76.     m_Lightambient[1] = 0.3f;
  77.     m_Lightambient[2] = 0.3f;
  78.     m_Lightambient[3] = 1.0f;
  79.  
  80.     srand( (unsigned)time(NULL) );
  81.  
  82. }
  83.  
  84. CMy3DFontView::~CMy3DFontView()
  85. {
  86. }
  87.  
  88. BOOL CMy3DFontView::PreCreateWindow(CREATESTRUCT& cs)
  89. {
  90.     // TODO: Modify the Window class or styles here by modifying
  91.     //  the CREATESTRUCT cs
  92.  
  93.     return CView::PreCreateWindow(cs);
  94. }
  95.  
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CMy3DFontView drawing
  98.  
  99. void CMy3DFontView::OnDraw(CDC* pDC)
  100. {
  101.     CMy3DFontDoc* pDoc = GetDocument();
  102.     ASSERT_VALID(pDoc);
  103.  
  104.     // TODO: add draw code for native data here
  105.     CPalette* oldPalette;
  106.  
  107.     //Set logic palette
  108.     oldPalette = m_pDC->SelectPalette(&m_Palette, FALSE);
  109.     m_pDC->RealizePalette();
  110.     
  111.     wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC);
  112.     //DrawGLFont();
  113.     drawWithOpenGL();
  114.     SwapBuffers(m_pDC->GetSafeHdc());
  115.     wglMakeCurrent(m_pDC->GetSafeHdc(), NULL);
  116.     m_pDC->SelectPalette(oldPalette, FALSE);
  117. }
  118. void CMy3DFontView::drawWithOpenGL()
  119. {
  120.     CMainFrame* pFrame; 
  121.     char scorePhrase[200];
  122.  
  123.     glShadeModel(GL_SMOOTH);
  124.     glEnable(GL_DEPTH_TEST);
  125.     
  126.     //clear color buffer
  127.     glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
  128.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  129.     
  130.     //set light model
  131.     glLightfv(GL_LIGHT0, GL_AMBIENT, m_Lightambient);//set light ambient
  132.     glLightfv(GL_LIGHT0, GL_DIFFUSE, m_Lightdiffuse);//set light specular
  133.     glLightfv(GL_LIGHT0, GL_SPECULAR, m_Lightspecular);//set light specular
  134.     glLightfv(GL_LIGHT0, GL_POSITION, m_Lightposition);//set light position
  135.  
  136.     glEnable(GL_LIGHTING);
  137.     glEnable(GL_LIGHT0);
  138.  
  139.     glMatrixMode(GL_MODELVIEW);
  140.     glLoadIdentity();
  141.  
  142.     if(autoRotate)
  143.         autoRotateDisplay();
  144.  
  145.     gluLookAt(cam.getX(), cam.getY(), cam.getZ(),
  146.               12.0f, 0.0f, -12.0f,
  147.               0.0f, 1.0f, 0.0f);
  148.  
  149.     glPushMatrix();
  150.         glTranslatef(-10.0f, -3.0f, 10.0f);
  151.         m_FontX.GLDrawText();
  152.     glPopMatrix();
  153.  
  154.     drawCubes();
  155.  
  156.  
  157.     sprintf(scorePhrase,"(space)drop(Cam 1/2)In/Out(Cam 3/4)Rot(Cam 5/6)Up/Dn  Score: %i", mat.score);
  158.  
  159.     VERIFY( pFrame = (CMainFrame*)GetParentFrame() ); 
  160.  
  161.     if(gameOver)
  162.     {
  163.         sprintf(scorePhrase,"Game Over Score %i",mat.score);
  164.         pFrame->SetWindowText(scorePhrase); 
  165.     }
  166.     else
  167.     {
  168.         pFrame->SetWindowText(scorePhrase); 
  169.     }
  170.  
  171.  
  172.     //draw the game grid
  173.     glRGB(0,255,0);
  174.     drawGrid();
  175.     
  176. }
  177. void CMy3DFontView::drawCubes()
  178. {
  179.     int color;
  180.  
  181.     //position the cube in the matrix position given by x, y, and z
  182.     GLfloat w, h, d;
  183.  
  184.     w = h = d = 5.0;  //cube is 5 x 5 x 5
  185.     for(int i = 0; i<MAT_WIDTH; ++i)
  186.         for(int j = 0; j<MAT_HEIGHT; ++j)
  187.             for(int k = 0; k<MAT_DEPTH; ++k)
  188.                 if(color = mat.isSet(i,j,k))
  189.                 {
  190.                     switch(color)
  191.                     {
  192.                         case 1: cvs.setAmbientMaterialColor(1,0,0,1);
  193.                             break;
  194.                         case 2: cvs.setAmbientMaterialColor(0,1,0,1);
  195.                             break;
  196.                         case 3: cvs.setAmbientMaterialColor(0,0,1,1);
  197.                             break;
  198.                         case 4: cvs.setAmbientMaterialColor(1,1,0,1);
  199.                             break;
  200.                         case 5: cvs.setAmbientMaterialColor(0,1,1,1);
  201.                             break;
  202.                         case 6: cvs.setAmbientMaterialColor(1,0,1,1);
  203.                             break;
  204.                     }
  205.                     glPushMatrix();
  206.                         glTranslatef(2.5+i*w, 2.5+j*h, -2.5 - k*h);
  207.                         cvs.Box(w,h,d);
  208.                     glPopMatrix();
  209.                 }
  210.  
  211. }
  212. /////////////////////////////////////////////////////////////////////////////
  213. // CMy3DFontView diagnostics
  214.  
  215. #ifdef _DEBUG
  216. void CMy3DFontView::AssertValid() const
  217. {
  218.     CView::AssertValid();
  219. }
  220.  
  221. void CMy3DFontView::Dump(CDumpContext& dc) const
  222. {
  223.     CView::Dump(dc);
  224. }
  225.  
  226. CMy3DFontDoc* CMy3DFontView::GetDocument() // non-debug version is inline
  227. {
  228.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy3DFontDoc)));
  229.     return (CMy3DFontDoc*)m_pDocument;
  230. }
  231. #endif //_DEBUG
  232.  
  233. /////////////////////////////////////////////////////////////////////////////
  234. // CMy3DFontView message handlers
  235.  
  236. int CMy3DFontView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  237. {
  238.     if (CView::OnCreate(lpCreateStruct) == -1)
  239.         return -1;
  240.     
  241.     // TODO: Add your specialized creation code here
  242.     PIXELFORMATDESCRIPTOR pfd =
  243.     {
  244.         sizeof(PIXELFORMATDESCRIPTOR),
  245.         1,
  246.         PFD_DRAW_TO_WINDOW|
  247.         PFD_SUPPORT_OPENGL|
  248.         PFD_DOUBLEBUFFER,  
  249.         PFD_TYPE_RGBA,
  250.         24,
  251.         0,0,0,0,0,0,
  252.         0,0,0,0,0,0,0,
  253.         32,
  254.         0,0,
  255.         PFD_MAIN_PLANE,
  256.         0,
  257.         0,0,0
  258.     };
  259.      
  260.     m_pDC = new CClientDC(this);
  261.     int pixelFormat =
  262.         ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd);
  263.     BOOL success = 
  264.         SetPixelFormat(m_pDC->GetSafeHdc(), pixelFormat, &pfd);
  265.  
  266.     DescribePixelFormat(m_pDC->GetSafeHdc(), pixelFormat,
  267.           sizeof(pfd), &pfd);
  268.  
  269.     if(pfd.dwFlags & PFD_NEED_PALETTE)
  270.          InitPalette();
  271.  
  272.     m_hRC = wglCreateContext(m_pDC->GetSafeHdc());
  273.  
  274.     m_FontX.SetXOffset(0.0f);
  275.     m_FontX.SetYOffset(0.1f);
  276.     m_FontX.SetXScale(6.4f);
  277.     m_FontX.SetYScale(6.3f);
  278.     m_FontX.SetZScale(3.8f);
  279.     m_FontX.SetXRotate(-90.0f);
  280.     m_FontX.SetYRotate(0.0f);
  281.     m_FontX.SetZRotate(0.0f);
  282.  
  283.     InitFontColor();
  284.  
  285.     wglMakeCurrent(m_pDC->m_hDC,m_hRC);
  286.     m_FontX.CreateFont(m_pDC, "Arial Black");
  287.     m_FontX.SetText("Cube Drop");
  288.  
  289.     wglMakeCurrent(NULL,NULL);
  290.  
  291.     setSpeed();
  292.  
  293.     startGame(); 
  294.  
  295.     return 0;
  296. }
  297.  
  298. void CMy3DFontView::OnDestroy() 
  299. {
  300.     CView::OnDestroy();
  301.     
  302.     // TODO: Add your message handler code here
  303.     wglDeleteContext(m_hRC);
  304.     m_Palette.DeleteObject();
  305.     ReleaseDC(m_pDC);
  306. }
  307.  
  308. void CMy3DFontView::OnSize(UINT nType, int cx, int cy) 
  309. {
  310.     GLdouble aspect;
  311.     CView::OnSize(nType, cx, cy);
  312.  
  313.     if (cy==0)
  314.         aspect = (GLdouble)cx;
  315.     else
  316.         aspect = (GLdouble)cx/(GLdouble)cy;
  317.  
  318.     CClientDC clientDC(this);
  319.     wglMakeCurrent(clientDC.m_hDC, m_hRC);
  320.     glMatrixMode(GL_PROJECTION);
  321.     glLoadIdentity();
  322.     //glFrustum(-1.0, 1.0, -1.0, 1.0, 2.0, 7.0);
  323.     //glViewport(0, 0, cx, cy);
  324.  
  325.     setPerspectiveWindow(60,aspect,5,4000);
  326.     setViewport(0,0,cx,cy);
  327.     
  328.     wglMakeCurrent(NULL, NULL);
  329. }
  330.  
  331.  
  332. void CMy3DFontView::InitPalette(void)
  333. {
  334.     PIXELFORMATDESCRIPTOR pfd;  // Pixel Format Descriptor         
  335.     LOGPALETTE *pPal;            // Pointer to memory for logical palette
  336.     int PixelFormat;            // Pixel format index
  337.     int paletteSize;            // Number of entries in palette 
  338.     BYTE RedMask;               // Range for each color entry (7,7,and 3)
  339.     BYTE GreenMask;
  340.     BYTE BlueMask;
  341.     HDC hDC = GetDC()->GetSafeHdc();  //the context device                                 
  342.  
  343.     // Get the pixel format index and retrieve the pixel format description
  344.     PixelFormat = GetPixelFormat(hDC);
  345.     DescribePixelFormat(hDC, PixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
  346.     
  347.     
  348.     // Check whether the pixel format and the pixel type
  349.     if (!(pfd.dwFlags & PFD_NEED_PALETTE ||
  350.       pfd.iPixelType == PFD_TYPE_COLORINDEX))
  351.         return;
  352.  
  353.     // Get the number of entries in palette. 256 colors for 8 bits 
  354.     paletteSize = 1 << pfd.cColorBits;
  355.     
  356.     // Allocate for the logical palette
  357.     pPal = (LOGPALETTE*)
  358.     malloc(sizeof(LOGPALETTE) + paletteSize * sizeof(PALETTEENTRY));
  359.     
  360.     
  361.     // Fill the logical palette header information 
  362.     pPal->palVersion = 0x300;            //support Windows3.0
  363.     pPal->palNumEntries = paletteSize;   //number of colors entries
  364.  
  365.     // Set the 1st entries of logical palette with the current system palette 
  366.     (void) GetSystemPaletteEntries(hDC, 0, paletteSize, &pPal->palPalEntry[0]);
  367.  
  368.     //Set the RGB mask
  369.     RedMask = (1 << pfd.cRedBits) - 1;
  370.     GreenMask = (1 << pfd.cGreenBits) - 1;
  371.     BlueMask = (1 << pfd.cBlueBits) - 1;
  372.  
  373.     //Set all entries of the logical palette 
  374.     for (int i=0; i<paletteSize; ++i) 
  375.     {
  376.         pPal->palPalEntry[i].peRed =
  377.             (((i >> pfd.cRedShift) & RedMask) * 255) / RedMask;
  378.         pPal->palPalEntry[i].peGreen =
  379.             (((i >> pfd.cGreenShift) & GreenMask) * 255) / GreenMask;
  380.         pPal->palPalEntry[i].peBlue =
  381.             (((i >> pfd.cBlueShift) & BlueMask) * 255) / BlueMask;
  382.         pPal->palPalEntry[i].peFlags = 0;
  383.     }
  384.  
  385.     //Create the palette
  386.     m_Palette.CreatePalette(pPal);
  387.  
  388.     //Free the memory allocated for the logical palette 
  389.     free(pPal);
  390. }
  391.  
  392.  
  393. void CMy3DFontView::DrawGLFont(void)
  394. {
  395.     glShadeModel(GL_SMOOTH);
  396.     glEnable(GL_DEPTH_TEST);
  397.     
  398.     //clear color buffer
  399.     glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
  400.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  401.     
  402.     //set light model
  403.     glEnable(GL_LIGHTING);
  404.     glEnable(GL_LIGHT0);
  405.  
  406.     glMatrixMode(GL_MODELVIEW);
  407.     glLoadIdentity();
  408.  
  409.     glTranslatef(-3.0f, -5.0f, -60.0f);
  410.  
  411.     m_FontX.GLDrawText();
  412.  
  413.     glFlush();
  414.  
  415. }
  416.  
  417.  
  418. void CMy3DFontView::InitFontColor()
  419. {
  420.     float fv[4];
  421.  
  422.  
  423.     fv[0] = 0.1;
  424.     fv[1] = 0.1;
  425.     fv[2] = 0.1;
  426.     fv[3] = 0.1;
  427.     m_FontX.SetEmission(fv);
  428.  
  429.     fv[0] = 0.9;
  430.     fv[1] = 0.9;
  431.     fv[2] = 0.9;
  432.     fv[3] = 1.0;
  433.     m_FontX.SetSpecular(fv);
  434.  
  435.     fv[0] = 0.1;
  436.     fv[1] = 0.1;
  437.     fv[2] = 1.0;
  438.     fv[3] = 1.0;
  439.     m_FontX.SetAmbient(fv);
  440.  
  441.     fv[0] = 0.1;
  442.     fv[1] = 0.1;
  443.     fv[2] = 0.1;
  444.     fv[3] = 1.0;
  445.     m_FontX.SetDiffuse(fv);
  446.  
  447.     m_FontX.SetShininess(0.1f);
  448.     
  449. }
  450.  
  451.  
  452. void CMy3DFontView::setPerspectiveWindow(GLdouble fovy, GLdouble aspect,GLdouble zNear,GLdouble zFar)
  453. {
  454.   glMatrixMode(GL_PROJECTION);
  455.   glLoadIdentity();
  456.   gluPerspective(fovy, aspect,zNear,  zFar);
  457. }
  458. void CMy3DFontView::setViewport(GLint iX, GLint iY, GLsizei iWidth, GLsizei iHeight)
  459. {
  460.     glViewport(iX,iY,iWidth,iHeight);
  461. }
  462. void CMy3DFontView::setDepthBuffer()
  463. {
  464.   glEnable(GL_DEPTH_TEST);
  465.   glDepthFunc(GL_LESS);
  466.   glEnable(GL_CULL_FACE);
  467.   glCullFace(GL_BACK);
  468.   glFrontFace(GL_CCW);
  469. }
  470. void CMy3DFontView::startGame()
  471. {
  472.     gameOver = FALSE;
  473.     autoRotate = FALSE;
  474.     cam.SetCamera(PI/2.0, 14.0f, 90.0f);
  475.     mat.SetScore(0);
  476.     mat.SetLevel(0);
  477.     //mat.SetTitleBar();
  478.     mat.ZeroMatrix();        
  479.     mat.set(3,10,3);
  480.     
  481.     //prevent two sets of timers from running if the game is reset
  482.     if(!timersSet)
  483.     {
  484.         //glutTimerFunc(delayTime,TimerFunction, delayTime);
  485.         //glutTimerFunc(10000, IncreaseSpeed, 10000);
  486.         timersSet = TRUE;
  487.     }    
  488. }
  489.  
  490.  
  491. void CMy3DFontView::OnTimer(UINT nIDEvent) 
  492. {
  493.     // TODO: Add your message handler code here and/or call default
  494.  
  495.     BOOL successful;
  496.  
  497.     if(pause)
  498.     {
  499.         KillTimer(1);
  500.     }
  501.     else
  502.     {
  503.         if(autoRotate)
  504.         {
  505.             SetTimer(1,5,0);
  506.         }
  507.         else
  508.         {
  509.             setSpeed();
  510.             successful = mat.moveDown();
  511.             if(!successful)
  512.             {
  513.                 gameOver = TRUE;
  514.                 autoRotate = TRUE;
  515.             }
  516.         }
  517.         //printf("Delay Time: %i\n", delayTime);
  518.     }
  519.  
  520.  
  521.     Invalidate(FALSE);
  522.  
  523.     CView::OnTimer(nIDEvent);
  524. }
  525.  
  526. void CMy3DFontView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  527. {
  528.     // TODO: Add your message handler code here and/or call default
  529.  
  530.         if (nChar==37)
  531.         {
  532.             if(!pause) mat.moveLeft(); 
  533.         }
  534.         else if(nChar==39)
  535.         {
  536.             if(!pause) mat.moveRight(); 
  537.         }
  538.  
  539.         else if(nChar==38)
  540.         {
  541.             if(!pause) mat.moveIn();
  542.         }
  543.         else if(nChar==40)
  544.         {
  545.             if(!pause) mat.moveOut();
  546.         }
  547.         else if(nChar==32)
  548.         {
  549.             mat.drop(); 
  550.         }
  551.         //1
  552.         else if(nChar==49)
  553.         {
  554.             cam.Out();
  555.         }
  556.             //2
  557.         else if(nChar==50)
  558.         {
  559.             cam.In();
  560.         }
  561.             //3
  562.         else if(nChar==51)
  563.         {
  564.             cam.RotateC();
  565.         }
  566.             //4
  567.         else if(nChar==52)
  568.         {
  569.             cam.RotateCC();
  570.         }
  571.             //5
  572.         else if(nChar==53)
  573.         {
  574.             cam.Up();    
  575.         }
  576.             //6
  577.         else if(nChar==54)
  578.         {
  579.             cam.Down();
  580.         }
  581.             //7
  582.         else if(nChar==55)
  583.         {
  584.         }
  585.             //8
  586.         else if (nChar==56)
  587.         {
  588.             
  589.         }
  590.  
  591.     Invalidate(FALSE);
  592.     CView::OnKeyDown(nChar, nRepCnt, nFlags);
  593. }
  594. void CMy3DFontView::drawGrid()
  595. {
  596.     int r,c,d = 0;
  597.     int nStep = 5;
  598.     int width = cvs.gameWidth;
  599.     int depth = cvs.gameDepth;
  600.     int height = cvs.gameHeight;
  601.  
  602.  
  603.  
  604.     glPushAttrib(GL_LIGHTING_BIT);
  605.     glDisable(GL_LIGHTING);
  606.  
  607.     glPushMatrix();
  608.  
  609.     glBegin(GL_LINES);
  610.  
  611.     //draw transverse grid lines
  612.     for(r = 0; r  <= width; r += nStep)
  613.     {
  614.         glVertex3d(r, height, 0);
  615.         glVertex3d(r, 0, 0);
  616.  
  617. //        for(d = 0; d <= height; d += nStep)
  618.         {
  619.             glVertex3d(r, d, 0);
  620.             glVertex3d(r, d, -depth);
  621.         }
  622.  
  623.         glVertex3d(r, 0, -depth);
  624.         glVertex3d(r, height, -depth);
  625.     }
  626.  
  627.     //draw lateral grid lines
  628.     for(c = 0; c <= depth; c += nStep)
  629.     {
  630.         glVertex3d(0, height, -c);
  631.         glVertex3d(0, 0, -c);
  632.  
  633. //        for(d = 0; d <= height; d += nStep)
  634.         {
  635.             glVertex3d(0, d, -c);
  636.             glVertex3d(width, d, -c);
  637.         }
  638.  
  639.         glVertex3d(width, 0, -c);
  640.         glVertex3d(width, height, -c);
  641.     }
  642.  
  643.     //draw grid lines up the y axis
  644.     for(d=0; d<=height; d+=nStep)
  645.     {
  646.         glVertex3d(0,d,0);
  647.         glVertex3d(width,d,0);
  648.  
  649.         glVertex3d(width,d,0);
  650.         glVertex3d(width,d,-depth);
  651.  
  652.         glVertex3d(width,d,-depth);
  653.         glVertex3d(0,d,-depth);
  654.  
  655.         glVertex3d(0,d,-depth);
  656.         glVertex3d(0,d,0);
  657.     }
  658.  
  659.     glEnd();
  660.  
  661.   glPopMatrix();
  662.   glPopAttrib();
  663.   glEnable(GL_LIGHTING);
  664. }
  665.  
  666. void CMy3DFontView::OnViewAuto() 
  667. {
  668.     // TODO: Add your command handler code here
  669.     autoRotate=TRUE;
  670. }
  671. void CMy3DFontView::autoRotateDisplay()
  672. {
  673.     static int movement = 0;
  674.     static int count = 0;
  675.  
  676.     //only change the direction of change
  677.     //on even multiples of 125
  678.     if(count%125 == 0)
  679.     {
  680.         movement = rand()%6+1;
  681.     }
  682.  
  683.     //only change the view when count is an even multiple of 2
  684.     //if the graphics card is very slow, decrease this
  685.     if(count%1 == 0)
  686.     {
  687.         switch(movement)
  688.         {
  689.             case 1: cam.Up(); break;
  690.             case 2: cam.Down(); break;
  691.             case 3: cam.RotateCC(); break;
  692.             case 4: cam.RotateC(); break;
  693.             case 5: cam.In(); break;
  694.             case 6: cam.Out(); break;
  695.         }
  696.     }
  697.  
  698.     ++count;
  699.  
  700. }
  701.  
  702. void CMy3DFontView::OnViewDefault() 
  703. {
  704.     // TODO: Add your command handler code here
  705.     autoRotate=FALSE;    
  706.     pause=FALSE;
  707.     cam.SetCamera(PI/2.0, 12.0f, 90.0f);
  708. }
  709.  
  710. void CMy3DFontView::OnFilePause() 
  711. {
  712.     // TODO: Add your command handler code here
  713.     pause=TRUE;
  714. }
  715. void CMy3DFontView::setSpeed()
  716. {
  717.     SetTimer(1,1000-mat.GetLevel(),0);
  718. }
  719.  
  720. void CMy3DFontView::OnFileNew() 
  721. {
  722.     // TODO: Add your command handler code here
  723.     startGame();
  724. }
  725.  
  726. void CMy3DFontView::OnFileResume() 
  727. {
  728.     // TODO: Add your command handler code here
  729.  
  730.         pause=FALSE;
  731.         setSpeed();
  732. }
  733.  
  734. void CMy3DFontView::OnViewAutostop() 
  735. {
  736.     // TODO: Add your command handler code here
  737.     autoRotate=FALSE;
  738. }
  739.